{extend name="layout" /}
{block name="body"}
<link rel="stylesheet" type="text/css" href="/static/js/bootstrap-datepicker/bootstrap-datepicker3.min.css">
<link rel="stylesheet" type="text/css" href="/static/js/bootstrap-datetimepicker/bootstrap-datetimepicker.min.css">
<link rel="stylesheet" type="text/css" href="/static/js/bootstrap-clockpicker/bootstrap-clockpicker.min.css">
<div class="row">
    <div class="col-lg-12">
        <div class="card">
            <div class="card-body">
                <form name="userinfo">
                    <div class="form-group">
                        <label for="username">用户名</label>
                        <input type="hidden" class="form-control" id="id" name="id" value="{$user.id}">
                        <input type="text" class="form-control" id="username" name="username" value="{$user.username}" disabled>
                    </div>
                    <div class="form-group">
                        <label for="nickname">昵称</label>
                        <input type="text" class="form-control" id="nickname" name="nickname" value="{$user.nickname}"
                            placeholder="请输入昵称">
                    </div>
                    <div class="form-group">
                        <label for="sex">性别</label>
                        <select class="form-control" id="sex" name="sex">
                            <option value="" disabled>请选择性别</option>
                            <option value="0" {if $user['sex']==0 }selected{/if}>男</option>
                            <option value="1" {if $user['sex']==1 }selected{/if}>女</option>
                        </select>
                    </div>
                    <div class="form-group file-group">
                        <label for="usertx">用户头像</label>
                        <div class="input-group">
                            <input type="text" class="form-control file-value" value="{$user.usertx}" name="usertx"
                                value="" placeholder="用户头像" />
                            <input type="file" name="file" accept=".png,.jpg,.jpeg,.bmp,.gif" style="display: none"
                                style="display: none;" />
                            <div class="input-group-btn">
                                <button class="btn btn-default file-browser" type="button">上传图片</button>
                            </div>
                        </div>
                    </div>
                    <div class="form-group file-group">
                        <label for="userbg">用户背景</label>
                        <div class="input-group">
                            <input type="text" class="form-control file-value" value="{$user.userbg}" name="userbg"
                                value="" placeholder="用户背景" />
                            <input type="file" name="file" accept=".png,.jpg,.jpeg,.bmp,.gif" style="display: none"
                                style="display: none;" />
                            <div class="input-group-btn">
                                <button class="btn btn-default file-browser" type="button">上传图片</button>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="password">用户密码</label>
                        <input type="text" class="form-control" id="password" name="password" placeholder="为空则不修改">
                    </div>
                    <div class="form-group">
                        <label for="useremail">邮箱</label>
                        <input type="text" class="form-control" id="useremail" name="useremail" value="{$user.useremail}"
                            placeholder="请输入邮箱">
                    </div>
                    <div class="form-group">
                        <label for="signature">个性签名</label>
                        <input type="text" class="form-control" id="signature" name="signature" value="{$user.signature}"
                            placeholder="请输入个性签名">
                    </div>
                    <div class="form-group">
                        <label for="viptime">VIP时间</label>
                        <input class="form-control" type="text" data-provide="datetimepicker" id="viptime" name="viptime"	placeholder="请选择具体时间" value="{$user['viptime']|date='Y-m-d H:i:s'}" data-side-by-side="true" 
					data-format="YYYY-MM-DD HH:mm:ss" />
                    </div>
                    <div class="form-group">
                        <label for="money">金币</label>
                        <input type="text" class="form-control" id="money" name="money" value="{$user.money}" placeholder="请输入余额">
                    </div>
                    <div class="form-group">
                        <label for="exp">邀请码</label>
                        <input type="text" class="form-control" id="invitecode" name="invitecode" value="{$user.invitecode}" disabled>
                    </div>
                    <div class="form-group">
                        <label for="reasons">是否封禁</label>
                        <div class="custom-control custom-switch">
                            {if $user.reasons == 1}
                            <input type="checkbox" class="custom-control-input" id="reasons" value="1" name="reasons"
                                onchange="changenone()" checked>
                            {else /}
                            <input type="checkbox" class="custom-control-input" id="reasons" value="0" name="reasons"
                                onchange="changenone()">
                            {/if}
                            <label class="custom-control-label" for="reasons"></label>
                        </div>
                    </div>
                    <div class="form-group" id="select_else" {if $user['reasons']==0} style="display: none;" {/if}>
                        <label for="reasons_ban">封禁理由</label>
                        <input type="text" class="form-control" id="reasons_ban" name="reasons_ban" value="{$user.reasons_ban}"
                            placeholder="请输入封禁理由">
                    </div>
                    <button type="button" onclick="updateuser()" class="btn btn-w-sm btn-primary mb-2">提交</button>
                    <button type="button" class="btn btn-default mb-2"
                        onclick="javascript:history.back(-1);return false;">返
                        回
                    </button>
                </form>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="js"}
<!--时间日期选择器-->
<script type="text/javascript" src="/static/js/momentjs/moment.min.js"></script>
<script type="text/javascript" src="/static/js/bootstrap-datetimepicker/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript" src="/static/js/momentjs/locale/zh-cn.min.js"></script>
<script>
    function changenone() {
        var reasons = $("#reasons").prop("checked");
        if (reasons) {
            $("#select_else").show();
        } else {
            $("#select_else").hide();
        }
    }

    function updateuser() {
        var l = $('body').lyearloading({
            opacity: 0.2,
            spinnerSize: 'lg',
            spinnerText: '后台处理中，请稍后...',
            textColorClass: 'text-info',
            spinnerColorClass: 'text-info'
        });
        $("#username").removeAttr("disabled");
        $.ajax({
            type: "POST",
            url: "{:url('user/edit')}",
            data: $("form").serializeArray(),
            dataType: "json",
            success: function (data) {
                $("#username").attr("disabled", "true");
                setTimeout(function () {
                    l.destroy();
                }, 1e3)
                if (data.code == 1) {
                    notify.success(data.msg);
                } else {
                    notify.error(data.msg);
                }
            },
            error: function () {
                $("#username").attr("disabled", "true");
                l.destroy();
                notify.error("系统错误");
            }
        })
    }

</script>
{/block}